| Conditions | 3 |
| Total Lines | 96 |
| Code Lines | 84 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { useDispatch, useSelector } from 'react-redux'; |
||
| 9 | |||
| 10 | |||
| 11 | export default function Header() { |
||
| 12 | |||
| 13 | const {isLoggedIn, token, user, role} = useSelector((state: RootState) => state.auth); |
||
| 14 | const dispatch = useDispatch(); |
||
| 15 | const navigate = useNavigate(); |
||
| 16 | |||
| 17 | const logOutUser = async () => { |
||
| 18 | dispatch(setLoggedInOut(false)); |
||
| 19 | dispatch(setCurrentUser(null)); |
||
| 20 | dispatch(setToken('')); |
||
| 21 | dispatch(setRole('customer')); |
||
| 22 | navigate('/') |
||
| 23 | console.log("Header here"); |
||
| 24 | } |
||
| 25 | |||
| 26 | const getAuthStatus = async () => { |
||
| 27 | const response = await axios.get(`${API_URL}/auth/status`, getHeader(token)); |
||
| 28 | console.log(response); |
||
| 29 | } |
||
| 30 | |||
| 31 | const getAuthMe = async () => { |
||
| 32 | const response = await axios.get(`${API_URL}/auth/me`, getHeader(token)); |
||
| 33 | console.log(response); |
||
| 34 | } |
||
| 35 | |||
| 36 | return ( |
||
| 37 | <> |
||
| 38 | |||
| 39 | |||
| 40 | <nav className="bg-white border-gray-200 dark:bg-gray-900"> |
||
| 41 | <div className="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4"> |
||
| 42 | <Link to="/" className="flex items-center space-x-3 rtl:space-x-reverse"> |
||
| 43 | <img src={logo} className="h-8" alt="Flowbite Logo" /> |
||
| 44 | <span className="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Hemåt</span> |
||
| 45 | </Link> |
||
| 46 | <button data-collapse-toggle="navbar-default" type="button" className="inline-flex items-center p-2 w-10 h-10 justify-center text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600" aria-controls="navbar-default" aria-expanded="false"> |
||
| 47 | <span className="sr-only">Open main menu</span> |
||
| 48 | <svg className="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 17 14"> |
||
| 49 | <path stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M1 1h15M1 7h15M1 13h15"/> |
||
| 50 | </svg> |
||
| 51 | </button> |
||
| 52 | <div className="hidden w-full md:block md:w-auto" id="navbar-default"> |
||
| 53 | <ul className="font-medium flex flex-col p-4 md:p-0 mt-4 border border-gray-100 rounded-lg bg-gray-50 md:flex-row md:space-x-8 rtl:space-x-reverse md:mt-0 md:border-0 md:bg-white dark:bg-gray-800 md:dark:bg-gray-900 dark:border-gray-700"> |
||
| 54 | <li> |
||
| 55 | <Link to="/adminmapnavigation" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 |
||
| 56 | dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">Karta</Link> |
||
| 57 | </li> |
||
| 58 | <li> |
||
| 59 | <Link to="/adminstartpage" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 |
||
| 60 | dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">Admin Start Page</Link> |
||
| 61 | </li> |
||
| 62 | <li> |
||
| 63 | <Link to="/customerstartpage" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 |
||
| 64 | dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">Customer Start Page</Link> |
||
| 65 | </li> |
||
| 66 | <li> |
||
| 67 | <Link to="/userlistpage" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 |
||
| 68 | dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">User List Page</Link> |
||
| 69 | </li> |
||
| 70 | <li> |
||
| 71 | <Link to="/userinfopage" className="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 |
||
| 72 | dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">User Info Page</Link> |
||
| 73 | </li> |
||
| 74 | |||
| 75 | </ul> |
||
| 76 | </div> |
||
| 77 | </div> |
||
| 78 | </nav> |
||
| 79 | |||
| 80 | |||
| 81 | <div className='flex justify-center items-center min-h-screen'> |
||
| 82 | <div className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700 overflow-hidden "> |
||
| 83 | |||
| 84 | <p className="font-normal text-gray-700 dark:text-gray-400">Logged In: <b>{isLoggedIn.toString()}</b></p> |
||
| 85 | <p className="font-normal text-gray-700 dark:text-gray-400">Token: <b>{token ? token : "Empty"}</b></p> |
||
| 86 | <p className="font-normal text-gray-700 dark:text-gray-400">Role: <b>{role}</b></p> |
||
| 87 | <p className="font-normal text-gray-700 dark:text-gray-400">User: <b>{user ? JSON.stringify(user) : "No User"}</b></p> |
||
| 88 | |||
| 89 | <button type="button" className="focus:outline-none text-white bg-red-700 |
||
| 90 | focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 |
||
| 91 | py-2.5 me-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 |
||
| 92 | dark:focus:ring-red-900" onClick={logOutUser}>Logout</button> |
||
| 93 | |||
| 94 | <button type="button" className="focus:outline-none text-white bg-red-700 |
||
| 95 | focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 |
||
| 96 | py-2.5 me-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 |
||
| 97 | dark:focus:ring-red-900" onClick={getAuthStatus}>Prompt auth/status in console</button> |
||
| 98 | <button type="button" className="focus:outline-none text-white bg-red-700 |
||
| 99 | focus:ring-4 focus:ring-red-300 font-medium rounded-lg text-sm px-5 |
||
| 100 | py-2.5 me-2 mb-2 dark:bg-red-600 dark:hover:bg-red-700 |
||
| 101 | dark:focus:ring-red-900" onClick={getAuthMe}>Prompt auth/me in console</button> |
||
| 102 | </div> |
||
| 103 | </div> |
||
| 104 | </> |
||
| 105 | ) |
||
| 107 |